package com.weita.lightfood.model.dao;


import com.weita.lightfood.model.entity.User;
import com.weita.lightfood.model.query.user.RegisterUserQuery;
import com.weita.lightfood.model.vo.user.UserCustomizedDishVo;
import com.weita.lightfood.model.vo.user.UserHistoryWeight;
import com.weita.lightfood.model.vo.user.UserWeightVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.io.IOException;
import java.util.List;

/**
 * @author IT_Monster at 2019/03/26 17:05.
 */
@Mapper
@Repository
public interface UserDao {
    /**
     * 通过id获取用户信息
     * @param userId
     * @return
     * @throws Exception
     */
    User getByID(int userId) throws Exception;

    /**
     * 获取所有用户信息
     * @return
     * @throws Exception
     */
    List<User> getAll() throws Exception;

    /**
     * 修改用户信息(不包括密码)
     * @param user
     * @throws Exception
     */
    void update(User user) throws Exception;

    /**
     * 通过id删除用户
     * @param userId
     * @throws Exception
     */
    void delete(int userId) throws Exception;

    /**
     * 通过用户id获取用户密码
     * @param userId
     * @return
     * @throws Exception
     */
    String getPwdById(int userId) throws Exception;

    /**
     * 修改用户密码
     * @param userId
     * @param pwd
     * @throws Exception
     */
    void updatePwd(@Param("userId") int userId, @Param("pwd") String pwd) throws Exception;

    /**
     * 通过用户名修改密码
     * @param userName
     * @param pwd
     * @throws Exception
     */
    void updatePwdByName(@Param("userName") String userName, @Param("pwd") String pwd) throws Exception;

    /**
     * 验证用户登陆
     * @param userName
     * @param pwd
     * @return
     * @throws Exception
     */
    User login(@Param("userName") String userName, @Param("pwd") String pwd) throws Exception;

    /**
     * 注册用户
     * @param registerUserQuery
     * @throws Exception
     */
    void registerUser(RegisterUserQuery registerUserQuery) throws Exception;

    /**
     * 通过用户名获取用户
     * @param userName
     * @return
     * @throws Exception
     */
    User getByUserName(String userName) throws Exception;

    /**
     * 通过用户名获取该用户密保问题
     * @param userName
     * @return
     * @throws Exception
     */
    String getSecurityQuestion(String userName) throws Exception;

    /**
     * 获取用户密保问题答案
     * @param userName
     * @return
     * @throws Exception
     */
    String getSecurityAnswer(String userName) throws Exception;

    /**
     * 获取用户初始体重，目标体重，最新体重
     * @param userId
     * @return
     * @throws Exception
     */
    UserWeightVo getWeight(int userId) throws Exception;

    /**
     * 记录用户最新体重
     * @param userId
     * @param newWeight
     * @throws Exception
     */
    void recordWeight(@Param("userId") int userId, @Param("newWeight") double newWeight) throws Exception;

    /**
     * 保存用户formId
     * @param formId
     * @param name
     * @throws Exception
     */
    void saveFormId(@Param("formId") String formId, @Param("name") String name) throws Exception;

    /**
     * 通过用户id从用户表中获取定制用户饮食所需要的数据
     * @param userId
     * @return
     * @throws Exception
     */
    UserCustomizedDishVo getCustomizedDishData(int userId) throws Exception;

    /**
     * 通过用户id获取用户formId
     * @param userId
     * @return
     * @throws Exception
     */
    String getFormId(int userId) throws Exception;

    /**
     * 记录用户历史体重
     * @param userId    用户id
     * @param weight    用户体重
     * @param date      记录日期
     */
    void recordHistoryWeight(@Param("userId") int userId, @Param("weight") double weight, @Param("date") String date);

    /**
     *  获取用户历史体重记录
     * @param userId
     * @return
     * @throws Exception
     */
    List<UserHistoryWeight> getHistoryWeight(@Param("userId") int userId) throws Exception;

    /**
     * 获取用户openId
     * @param userId
     * @return
     * @throws IOException
     */
    String getOpenId(@Param("userId") int userId) throws IOException;

    /**
     *  设置用户用户openid
     * @param userId
     * @param newOpenId
     * @throws IOException
     */
    void setOpenId(@Param("userId") int userId, @Param("newOpenId") String newOpenId) throws IOException;
}
